use shq_pas_etl::run_cli;
use tracing::Level;
use tracing_subscriber::{filter::EnvFilter, prelude::*};
use shq_pas_etl::get_work_path;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    dotenv::dotenv().ok();
    let filter1 = EnvFilter::from_default_env()
        .add_directive("clickhouse_rs=WARN".parse()?)
        .add_directive(Level::INFO.into());
    let filter2 = EnvFilter::from_default_env()
        .add_directive("clickhouse_rs=WARN".parse()?)
        .add_directive(Level::INFO.into());
    let stdout_log = tracing_subscriber::fmt::layer().pretty();
    let path = format!("{}/logs",get_work_path());
    let file_appender = tracing_appender::rolling::daily(&path, "pas_etl.log");
    let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
    let file_subscriber = tracing_subscriber::fmt::layer().with_writer(non_blocking);
    tracing_subscriber::registry()
        .with(stdout_log.with_filter(filter1))
        .with(file_subscriber.with_filter(filter2))
        .init();
    crate::run_cli().await;
    log::logger().flush();
    Ok(())
}
